/**
 * @param {number[]} nums
 * @return {number[][]}
 */

var permute = function (nums) {
    let len = nums.length
    let res = []
    let queue = []
    backtrack([])
    return res
    function backtrack(arr) {
        if (queue.length === len) {
            res.push(queue.slice())
            return
        }
        for (let i = 0; i < len; i++) {
            if (arr.some(item => item === nums[i])) {
                continue
            }
            arr.push(nums[i])
            queue.push(nums[i])
            backtrack(arr)
            queue.pop()
            arr.pop()
        }
    }
};